package com.project.collectAPI.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.collectAPI.dao.CurtaskDao;
import com.project.collectAPI.dao.CurtaskforsupermarketDao;
import com.project.collectAPI.entity.Curtask;
import com.project.collectAPI.entity.Curtaskforsupermarket;
import com.project.collectAPI.service.CurtaskforsupermarketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * (Curtaskforsupermarket)表服务实现类
 *
 * @author makejava
 * @since 2024-01-05 22:54:02
 */
@Service("curtaskforsupermarketService")
public class CurtaskforsupermarketServiceImpl extends ServiceImpl<CurtaskforsupermarketDao, Curtaskforsupermarket> implements CurtaskforsupermarketService {
    @Autowired
    CurtaskforsupermarketDao curtaskforsupermarketDao;

    @Override
    public String getTask() {
        Curtaskforsupermarket marketTask=curtaskforsupermarketDao.selectOne(new QueryWrapper<Curtaskforsupermarket>().orderByAsc("id").last("LIMIT 1"));
        String rct=marketTask.getTaskfirst()+":"+marketTask.getTasksecond()+":"+marketTask.getTaskname()+":"+marketTask.getId();
        return rct;
    }

    @Override
    public void setTask(int taskId,int firstArrIndex, int secondArrIndex,String TaskName,String secondarrays) {
        Curtaskforsupermarket taskData=curtaskforsupermarketDao.selectOne(new QueryWrapper<Curtaskforsupermarket>().eq("id",taskId));
        if(taskData==null){ //为空才插入新用户
            Curtaskforsupermarket newData=new Curtaskforsupermarket();
            newData.setTaskfirst(0);
            newData.setTasksecond(0);
            newData.setTaskname(TaskName);
            newData.setSecondarrays(secondarrays);
            curtaskforsupermarketDao.insert(newData);
        }else{
            taskData.setId(taskData.getId());
            taskData.setTaskfirst(firstArrIndex);
            taskData.setTasksecond(secondArrIndex);
            taskData.setTaskname(TaskName);
            taskData.setSecondarrays(secondarrays);
            //System.out.println("更新==》"+taskData);
            curtaskforsupermarketDao.updateById(taskData);
        }
    }

    @Override
    public void updateStatusById(int taskId, String status) {
        Curtaskforsupermarket taskData=new Curtaskforsupermarket();
        taskData.setId(taskId);
        taskData.setStatus(status);
        curtaskforsupermarketDao.updateById(taskData);
    }

    @Override
    public String getStatusById(int taskId) {
        Curtaskforsupermarket taskData=curtaskforsupermarketDao.selectOne(new QueryWrapper<Curtaskforsupermarket>().eq("id",taskId));
        return taskData.getStatus();
    }

    @Override
    public void updateSecondArrsById(int taskId, String secondarrays) {
        Curtaskforsupermarket taskData=new Curtaskforsupermarket();
        taskData.setId(taskId);
        taskData.setSecondarrays(secondarrays);
        curtaskforsupermarketDao.updateById(taskData);
    }

    @Override
    public String getSecondArrs(int taskId) {
        Curtaskforsupermarket taskData=curtaskforsupermarketDao.selectOne(new QueryWrapper<Curtaskforsupermarket>().eq("id",taskId));
        return taskData.getSecondarrays();
    }

    @Override
    public void updateDataFile(int taskId, Curtaskforsupermarket curtaskforsupermarket) {
        Curtaskforsupermarket taskData=new Curtaskforsupermarket();
        taskData.setId(taskId);
        curtaskforsupermarketDao.updateById(curtaskforsupermarket);
    }
}

